Skip to content

Conversation

@maor-rozenfeld
Copy link
Contributor

This PR adds automated PostgreSQL backups to the Docker Compose deployment.

Changes

  • Add postgres-backup service to docker-compose.yml
  • Configure daily backups with 7-day retention by default
  • Include backup script for automated database dumps
  • Update README with backup configuration and restore instructions
  • Add configurable backup schedule and retention via environment variables

Configuration

  • Schedule: Daily at 2 AM (configurable via BACKUP_SCHEDULE)
  • Retention: 7 days (configurable via BACKUP_RETENTION_DAYS)
  • Location: postgres_backups Docker volume

Fixes CI-135.

- Add postgres-backup service to docker-compose.yml
- Configure daily backups with 7-day retention by default
- Include backup script for automated database dumps
- Update README with backup configuration and restore instructions
- Add configurable backup schedule and retention via env vars

Fixes CI-135.
Copilot AI review requested due to automatic review settings January 7, 2026 20:16
@linear
Copy link

linear bot commented Jan 7, 2026

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 7, 2026

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements an automated PostgreSQL backup solution for the Docker Compose deployment. The implementation adds a dedicated backup service that runs scheduled database dumps with configurable retention policies.

Key Changes:

  • Added automated backup service with daily scheduling and 7-day retention by default
  • Implemented both single database and full cluster backup capabilities
  • Provided comprehensive documentation for backup configuration and restoration procedures

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
deploy/docker-compose/postgres-backup.sh Backup script implementing scheduled dumps, retention cleanup, and cron-based automation
deploy/docker-compose/docker-compose.yml Service definition for postgres-backup container with volume mounts and environment configuration
deploy/docker-compose/README.md Documentation covering backup configuration, scheduling, and restoration procedures
deploy/docker-compose/.env.defaults Default environment variables for backup schedule and retention settings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +28 to +29
--verbose \
2>&1 | gzip > "$backup_file"
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pg_dump stderr is being redirected and gzipped along with stdout due to 2>&1, which means verbose output and any error messages will be compressed into the backup file instead of being logged. This makes it difficult to diagnose backup failures. Remove --verbose or redirect stderr separately to preserve error logging while keeping only the SQL dump in the backup file.

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +60
--verbose \
2>&1 | gzip > "$backup_file"
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pg_dumpall stderr is being redirected and gzipped along with stdout due to 2>&1, which means verbose output and any error messages will be compressed into the backup file instead of being logged. This makes it difficult to diagnose backup failures. Remove --verbose or redirect stderr separately to preserve error logging while keeping only the SQL dump in the backup file.

Copilot uses AI. Check for mistakes.
Comment on lines +90 to +97
# Setup cron job
echo "$SCHEDULE root /usr/local/bin/backup-job.sh >> /var/log/backup.log 2>&1" > /etc/cron.d/postgres-backup
chmod 0644 /etc/cron.d/postgres-backup

# Create the backup job script
cat > /usr/local/bin/backup-job.sh << 'EOF'
#!/bin/bash
source /etc/environment
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cron job script calls perform_backup function but this function is defined in the main script, not in the backup-job.sh file. Exported bash functions are not available to cron jobs. The backup-job.sh script needs to either source the main script or have the perform_backup function definition copied into it.

Suggested change
# Setup cron job
echo "$SCHEDULE root /usr/local/bin/backup-job.sh >> /var/log/backup.log 2>&1" > /etc/cron.d/postgres-backup
chmod 0644 /etc/cron.d/postgres-backup
# Create the backup job script
cat > /usr/local/bin/backup-job.sh << 'EOF'
#!/bin/bash
source /etc/environment
# Determine absolute path to this script so cron job can source it
SCRIPT_PATH="$(readlink -f "$0")"
# Setup cron job
echo "$SCHEDULE root /usr/local/bin/backup-job.sh >> /var/log/backup.log 2>&1" > /etc/cron.d/postgres-backup
chmod 0644 /etc/cron.d/postgres-backup
# Create the backup job script
cat > /usr/local/bin/backup-job.sh << EOF
#!/bin/bash
source /etc/environment
# Source the main backup script to load perform_backup and related functions
source "$SCRIPT_PATH"

Copilot uses AI. Check for mistakes.

# Start cron in foreground
echo "Starting cron scheduler..."
cron && tail -f /var/log/cron.log /var/log/backup.log
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tail command attempts to follow /var/log/backup.log, but this file is never created. The cron job in line 91 redirects output to this location, but the file won't exist until the first scheduled backup runs. This will cause tail to fail if the file doesn't exist. Use tail -f /var/log/backup.log with the -F flag instead, or ensure the log file is created before tailing it.

Suggested change
cron && tail -f /var/log/cron.log /var/log/backup.log
cron && tail -F /var/log/cron.log /var/log/backup.log

Copilot uses AI. Check for mistakes.
timeout: 3s
retries: 3
postgres-backup:
image: 'postgres:14.4'
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The postgres:14.4 image is outdated and may contain known security vulnerabilities. PostgreSQL 14.4 was released in 2022. Consider using a more recent patch version within the 14.x series or upgrading to a newer major version to ensure security patches are applied.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants